package com.sunni.converter;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateConverter implements Converter<String,Date> { //<String(传入数据的类型),Date(要转成数据类型)>
    @Override
    public Date/*要转成的数据*/ convert(String dateStr/*传入的数据*/) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = simpleDateFormat.parse(dateStr);
        } catch (ParseException e) {
            System.out.println("e = " + e);
        }
        return date;
    }
}
